import type { FormInstance, FormRules } from 'element-plus'
import { LoginData } from '@/service/LoginService'

export type AccountKey = 'super' | 'admin' | 'user'

export interface Account {
  key: AccountKey
  label: string
  userName: string
  password: string
  roles: string[]
}

export const accounts = computed<Account[]>(() => [
  {
    key: 'super',
    label: '超级管理员',
    userName: 'Super',
    password: '123456',
    roles: ['R_SUPER']
  },
  {
    key: 'admin',
    label: '管理员',
    userName: 'Admin',
    password: '123456',
    roles: ['R_ADMIN']
  },
  {
    key: 'user',
    label: '普通用户',
    userName: 'User',
    password: '123456',
    roles: ['R_USER']
  }
])

export const formRef = ref<FormInstance>()

// export const loginForm = reactive({
//   account: '',
//   username: '',
//   password: '',
//     code:'',
//   rememberPassword: true
// })
export const loginForm = ref<LoginData>({
    tenantId: '000000',
    username: 'admin',
    password: '666666',
    rememberMe: false,
    code: '',
    uuid: ''
} as LoginData);

export const rules = computed<FormRules>(() => ({
  username: [{ required: true, message: '用户名不能为空', trigger: 'blur' }],
  password: [{ required: true, message: '密码不能为空', trigger: 'blur' }]
}))

// // 设置账号
// export const setupAccount = (key: AccountKey) => {
//   const selectedAccount = accounts.value.find((account: Account) => account.key === key)
//   loginForm.account = key
//   loginForm.username = selectedAccount?.userName ?? ''
//   loginForm.password = selectedAccount?.password ?? ''
// }
